<%@ page import="com.tlb.ejb.*,com.tlb.dto.*,com.tlb.web.*,java.util.*" %>
<%




Util util = Util.getUtil();
Poster p = new AuthManager(request, response).softAuthenticatePoster();
boolean adminUser = p != null && p.getUserLevelId()==1;


String pTid = request.getParameter("threadId");
String x = request.getParameter("x");
if (x == null || x.trim().equals("")) {
    x = "0";
}

if (pTid == null) {
    request.getRequestDispatcher("/index.jsp").forward(request, response);
}

ThreadFacade tFacade = new ThreadFacade((p == null ? 0 : p.getPosterId()), Integer.parseInt(pTid));


if(tFacade == null || !tFacade.theadExists()) {
    %>    
    Thread not found!
    <br><br>
    <a href="http://www.biglawboard.com">Back to the board.</a>
    <%
    return;
}

if(tFacade.getTOS()  && (p == null ||p.getUserLevelId() != 1)) {
    %>
        This thread has been removed due to a <b><a href="http://www.biglawboard.com/blb/policies.jsp">Terms Of Service violation</a>.</b>
        <br><br>
        Threads are flagged by BLB moderators.  If you wish to challenge the status of this thread, please email <a href="mailto:biglawboard@gmail.com">biglawboard@gmail.com</a>
        <br><br>
        <a href="http://www.biglawboard.com">Back to the board.</a>
    <%
    return;
}


List list = tFacade.getPosts();
Iterator it = list.iterator();
String hdrCont = null;
String pLink = null;
            
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>BLB: <%= tFacade.getThreadTitle() %></title>
        <link rel="shortcut icon" href="ext/c_sailboat.gif">
        <script type="text/javascript" src="ext/ajax.js"></script>
        <link rel="stylesheet" type="text/css" href="ext/tlbStyle.css" />
        
                
        
        <script>
            var editInProg = false;
            var replyInProg = false;
            var loggedIn = <%= p == null ? "false" : "true" %>;
            
            function showReply(id, treeId, location) {
                if(!loggedIn) {
                    document.location = "login.jsp?action=reply&postId=" + id + "&threadId=<%=tFacade.getThreadId()%>" + "&treeId=" + treeId + "&x=" + x;
                    return;
                }
                
                //if(replyInProg) {
                //    document.getElementById('pa' + id).style.display = 'inline';
                //    document.getElementById('pa' + id).innerHTML = "<font color=red>Another reply on this page is in progress.  Save or cancel it before replying here.</font>";
                //    return;
                //}
                
                replyInProg = true;
                document.forms['replyForm'].treeId.value = treeId;
                document.getElementById('replyPostId').value=id;
                if(treeId > 1) {
                    document.getElementById('buttons' + id).style.display = 'none';
                    document.getElementById('pa' + id).style.display = 'inline';
                    document.getElementById('pa' + id).innerHTML = document.getElementById('replyTemplate').innerHTML;
                } else {
                    document.getElementById('newTreeBtn' + location).style.display = 'none';
                    document.getElementById('newTree' + location).style.display = 'inline';
                    document.getElementById('newTree' + location).innerHTML = document.getElementById('replyTemplate').innerHTML;
                }
            
        }
        
        function showEdit(id) {
            if(!loggedIn) {
                document.location = "login.jsp?action=edit&postId=" + id + "&threadId=<%=tFacade.getThreadId()%>";
                return;
            }
            //if(editInProg) {
            //    document.getElementById('pa' + id).style.display = 'inline';
            //    document.getElementById('pa' + id).innerHTML = "<font color=red>Another edit on this page is in progress.  Save or cancel it before editing here.</font>";
            //    return;
            //}
            
            editInProg = true;
            
            document.getElementById('buttons' + id).style.display = 'none';
            document.getElementById('pa' + id).style.display = 'inline';
            document.getElementById('editPostId').value=id;
            document.getElementById('pa' + id).innerHTML = document.getElementById('editTemplate').innerHTML;
            
            if(document.getElementsByTagName("body")[0].innerText != undefined){
                document.getElementById('editTa').innerText = document.getElementById('ta' + id).innerHTML.replace(/<a href[^>]+>/gi,"");
                document.getElementById('editTa').innerText = document.getElementById('editTa').innerText.replace(/<\/a>/gi,"");
                document.getElementById('editTa').innerText = document.getElementById('editTa').innerText.replace(/<\/?p>/gi,"");
            } else{
            document.getElementById('editTa').textContent = document.getElementById('ta' + id).innerHTML.replace(/<a href[^>]+>/gi,"");
            document.getElementById('editTa').textContent = document.getElementById('editTa').textContent.replace(/<\/a>/gi,"");
            document.getElementById('editTa').textContent = document.getElementById('editTa').textContent.replace(/<\/?p>/gi,"");
        }
    }
    
    
    function submitEdit(form) {
        document.getElementById('editBtn').disabled=true;
        form.submit();
    }
    
    function submitReply(form) {
        document.getElementById('replyBtn').disabled=true;
        form.submit();
    }
    

    function flag(postId, flagId, adm) {
        if(adm != "true")
            adm = "false";
        sendAjax("action=flagPost&flagId=" + flagId + "&postId=" + postId + "&threadId=<%=tFacade.getThreadId()%>&adm=" + adm, flagCB);
    }



    function flagCB(respData) {
        var pid = respData.responseText;
        if(pid != null) {
            document.getElementById("flag" + pid.replace(/[\n\r]+/g, "")).innerHTML = '<i>Flagged - Thanks.</i>';
        }                
    }
    
    
        </script>
    </head>
    
    <body bgcolor="white" background="bkgrnd.jpg" >
        
        <center>
            <a name="_top"></a>
            <div id="threadContainer3">
                <table border=0 cellpadding=0 cellspacing=0 width=775>
                    <tr>
                        <td><%@ include file="header.jsp" %></td>
                    </tr>
                    <% if(p!=null && p.getUserLevelId() > 0) { %>
                    <tr>
                        <td align=right>
                            <b>Mod Bar:&nbsp;</b>
                            <span id="flag-99"><a href="javascript: flag(-99,10,'true')" class="flag"><%=tFacade.getSticky()?"Un-":""%>Sticky</a></span>
                            <span id="flag-98"><a href="javascript: flag(-98,11,'true')" class="flag"><%=tFacade.getTOS()?"Un-":""%>TOS</a></span>
                            <span id="flag-97"><a href="javascript: flag(-97,12,'true')" class="flag"><%=tFacade.getNSFW()?"Un-":""%>NSFW</a></span>
                            <span id="flag-96"><a href="javascript: flag(-96,13,'true')" class="flag"><%=tFacade.getSpam()?"Un-":""%>Spam</a></span>                            
                        </td>
                    </tr>
                    <%}%>
                </table>
                
                <br>
                
                <h3><%= tFacade.getThreadTitle() %></h3>
                <table border=0 cellpadding=0 cellspacing=0 width=775>
                    
             <!--**************THREAD MAP******************-->
             <%
             long avgPostTime = 0l;
             String fadeHex = null;
             while(it.hasNext()) {
                PostView post = (PostView) it.next();

                if(avgPostTime == 0l)
                    avgPostTime = ((tFacade.getMaxThreadDate().getTime()/1000 - tFacade.getMinThreadDate().getTime()/1000)/200l);

                int fade = (int)((post.getPostDate().getTime()/1000 - tFacade.getMinThreadDate().getTime()/1000)/(avgPostTime>0?avgPostTime:1));
                fade = fade > 255?255:fade;

                fadeHex = Integer.toHexString(fade).toUpperCase();
                if(fadeHex.length() == 1)
                    fadeHex = "0" + fadeHex;

                pLink = "<a href='#" + post.getPostId() + "'><font color='#" + fadeHex + "1700'>" + post.getContentTitle(p) + "</font></a>";

                %>
                <tr class="<%=post.getHidenReasonCSSClass(p)%>">
                <td><div style="margin-left:<%= post.getDepth() * 15 %>px"><%= pLink %></div></td>
                <td><%=new MonikerDAO().fixHTML(post.getMonikerName(), 30)%></td>
                <td><nobr><%= post.getPostDateFmt() %></nobr></td>
                </tr>
            <%}%>
            </table>
            <!--**************END OF THREAD MAP******************-->
            
            
            <table border=0 cellpadding=0 cellspacing=0 width=775>
                <tr>
                    <td colspan=3>

                        <br><br>
                        <span id='newTreeBtnTop'><a style="color:blue;text-decoration:none" href="<%=p != null && p.getInlineReply() == 1 ? "javascript: showReply(" + pTid + ", 0,'Top')" : "replyStart.jsp?action=reply&threadId=" + pTid + "&postId=" + pTid + "&treeId=0&x=" + x %>">Post New Message In This Thread</a></span>
                        <br><br>
                        <a href="index.jsp" style="color:blue;text-decoration:none">Back to Board</a>
                        <br>
                    </td>
                </tr>
                <tr>
                    <td colspan=3><div id="newTreeTop" style="display:none"></div></td>
                </tr>
            
            
            
            <!--**********THREAD CONTENTS***********-->
            <%
            it = list.iterator();
            while (it.hasNext()) {
                PostView post = (PostView) it.next();
                %>
                </table>
                <table border=0 cellpadding=0 cellspacing=0 width=775>
                    <tr>
                        <td colspan=3>
                            <a name="<%= post.getPostId() %>" /></a>
                            <div style="font-family:Times New Roman,MS Sans Serif;font-size:medium;margin-left:<%= post.getDepth() * 30 %>px">
                                <hr noshade size=1 width="100%">
                                <nobr>
                                <span class="<%=post.getHidenReasonCSSClass(p)%>"> <!--todo: fix post counter to optional -->


                                <!--<b>Author:</b> <%= new MonikerDAO().fixHTML(post.getMonikerName()) %> [<%= post.getPostCount() %>] (<i><%= new MonikerDAO().fixHTML(post.getTagLine()) %></i>)<br>-->
                                <%=util.getViewThreadAuthorString(post)%><br>
                                <p class="posted">Posted: <%= post.getPostDateFmt() %></p>
                                </span>
                                <span style="font-size: small">Flag:</span>
                                    <span id="flag<%= post.getPostId() %>">
                                        <a href="javascript: flag(<%= post.getPostId() %>, 1, 'false')" class="flag" title="Recommend thread for best of catagory">Best-Of</a> 
                                        <a href="javascript: flag(<%= post.getPostId() %>, 2, 'false')" class="flag" title="Useful law school or firm related information">Helpful</a> 
                                        <a href="javascript: flag(<%= post.getPostId() %>, 4, '<%=adminUser?"true":"false"%>')" class="flag" title="Post contains content you wouldn't want to see at work"><%=post.getNsfw()?"Un-":""%>NSFW</a>
                                        <a href="javascript: flag(<%= post.getPostId() %>, 3, '<%=adminUser?"true":"false"%>')" class="flag" title="Board cluttering content with no value"><%=post.getSpam()?"Un-":""%>Spam</a> 
                                        <a href="javascript: flag(<%= post.getPostId() %>, 5, '<%=adminUser?"true":"false"%>')" class="flag" title="Terms Of Service Violation.  Post will be hidden with enough votes."><%=post.getTos()?"Un-":""%>TOS Violation</a>
                                    </span><br>
                                </nobr>            
                                <br>
                                <div id=ta<%= post.getPostId() %>><%= post.getContentFormatted(p) %></div>
                                <br>
                                <span id="buttons<%= post.getPostId() %>" class="thdBtns">
                                    <input type=button class=btn onclick="javascript: document.location='#_top'" value=Top>
                                    <input value=Reply type=button class=btn onclick="<%=p != null && p.getInlineReply() == 1 ? "javascript: showReply(" + post.getPostId() + ", " + post.getTreeId() + ")" : "javascript: document.location='replyStart.jsp?action=reply&threadId=" + post.getThreadId() + "&postId=" + post.getPostId() + "&treeId=" + post.getTreeId() + "&x=" + x + "'"%>">

                                    <% if (p != null && p.getPosterId() == post.getPosterId()) {
                                    String link = " <input value=Edit type=button class=btn onclick=\"" + ((p != null && p.getInlineReply() == 1) ? "javascript: showEdit(" + post.getPostId() + ")" : "javascript: document.location='editStart.jsp?action=edit&threadId=" + post.getThreadId() + "&postId=" + post.getPostId() + "&x=" + x + "'") + "\">";
                                    %> 
                                    <%=link%>
                                    <% }%>
                                    <input value="Link" type=button class=btn onclick="javascript: document.getElementById('link<%= post.getPostId() %>').style.display='inline'">
                                    &nbsp; <span style="font-size:9px;color:black;display:none;" id="link<%= post.getPostId() %>">Link: http://www.big<%=Util.getUtil().getBoard(request) == Util.BCB ? "college" : "law"%>board.com/blb/viewThread.jsp?threadId=<%=pTid%>#<%=post.getPostId()%></span>
                                    <br><br>
                                </span>
                                <div id="pa<%= post.getPostId() %>" style="display:none"></div>
                            </div>
                        </td>
                    </tr>
                <%}%>
                </table>
                <!--**********END OF THREAD CONTENTS***********-->
                
                
                <hr noshade width=100%><br>
                <span id='newTreeBtnBottom'><a style="color:blue;text-decoration:none" href="<%=p != null && p.getInlineReply() == 1 ? "javascript: showReply(" + pTid + ", 0,'Bottom')" : "replyStart.jsp?action=reply&threadId=" + pTid + "&postId=" + pTid + "&treeId=0&x=" + x %>">Post New Message In This Thread</a></span>
                <div id="newTreeBottom" style="display:none"></div>
                <br><br>
                
                <a href="index.jsp" style="color:blue;text-decoration:none">Back to Board</a>
                <br><br>
                
<script type="text/javascript"><!--
google_ad_client = "pub-8991850096910369";
/* Bottom of ThreadView Page, 728x90 */
google_ad_slot = "6631824587";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>                
                
                
            </div>
            
            <% if (p != null && p.getPrimaryMoniker() != null) {%>
            <div id="replyTemplate" style="display: none">
                <form method=post action=replyPost.jsp name="replyForm">
                    <input type=hidden name=replyPostId id=replyPostId value=-1>
                    <input type=hidden name=threadId value="<%=tFacade.getThreadId()%>">
                    <input type=hidden name=x value="<%=x%>">
                    <input type=hidden name=treeId value="">
                    <table width=100% border=0>
                        <tr>
                            <td width=75><b>Moniker: </b></td>
                            <td>
                                <select name="monikerId">
                                    <option default value="<%= p.getPrimaryMoniker().getMonikerId() %>"><%= p.getPrimaryMoniker().getName() %></option>
                                    <%
     Set mons = p.getMonikers();
     mons.remove(p.getPrimaryMoniker());
     if (mons.size() > 0) {
         for (it = mons.iterator(); it.hasNext();) {
             Moniker mon = (Moniker) it.next();
             if (mon.getName().equals("Guest")) {
                 continue;
             }
                                    %><option value="<%= mon.getMonikerId() %>"><%= mon.getName() %></option>
                                    <%
         }
     }

                                    %>
                                    
                                    
                                </select>
                                &nbsp;<b>NSFW?</b> <input type=checkbox name=nsfw value=true> 
                            </td>
                        </tr>
                        <tr><td valign=top><b>Post: </b></td><td><textarea rows=10 cols=60 wrap=virtual name=content></textarea></td></tr>
                        <tr><td>&nbsp;</td><td><input onclick="submitReply(this.form)" type=button class=btn id="replyBtn" value="Save Reply">&nbsp;<input type=button class=btn value="Cancel" onclick="javascript: document.location='viewThread.jsp?threadId=<%=request.getParameter("threadId")%>&x=<%=x%>'"></td></tr>
                    </table>
                </form>
            </div>
            
            <div id="editTemplate" style="display: none">
                <form method=post action=editPost.jsp>
                    <input type=hidden name=editPostId id=editPostId value=-1>
                    <input type=hidden name=threadId value="<%=tFacade.getThreadId()%>">
                    <input type=hidden name=x value="<%=x%>">
                    <table width=100% border=0 cellpadding=0 cellspacing=1>
                        <tr><td width=75 valign=top><b>Edit Post: </b></td><td><textarea name=content id=editTa rows=10 cols=60 wrap=virtual></textarea></td></tr>
                        <tr><td>&nbsp;</td><td><input onclick="submitEdit(this.form)" type=button class=btn id="editBtn" value="Save Edit">&nbsp;<input type=button class=btn value="Cancel" onclick="javascript: document.location='viewThread.jsp?threadId=<%=tFacade.getThreadId()%>&x=<%=x%>'"></td></tr>
                    </table>
                </form>
            </div>
            
            <% } %>
            <!-- Start of StatCounter Code -->
            <script type="text/javascript">
                var sc_project=2753481; 
                var sc_invisible=0; 
                var sc_partition=27; 
                var sc_security="fadeb289"; 
            </script>
            <script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a class="statcounter" href="http://www.statcounter.com/"><img class="statcounter" src="http://c28.statcounter.com/2753481/0/fadeb289/0/" alt="blog stats" /></a></div></noscript>
            <!-- End of StatCounter Code -->
        </center>
    </body>
</html>

